<script setup lang="ts">
let selectInnerHTML = ref('')
let pageDocument = ref('111111')
const handleEvent = (event: any) => {
  const data = event.data
  pageDocument.value = '22222222';
  alert(data)
  pageDocument = data
  // 在这里处理接收到的消息
  console.log('Received message from parent:', data)
}
onMounted(() => {
  console.log(2222, 'iframe vue comp', window)
  const header = document.getElementById('aaa')
  console.log(header)
  console.log(window.parent)
  window.parent.postMessage('子页面发送的消息','http://a.index.com')
  window.addEventListener('message', handleEvent, false)
})
onUnmounted(() => {
  window.removeEventListener('message', handleEvent, false)
})
</script>

<template>
  <div>
    <!-- <h1 class="text-red-800 font-bold text-xl">
      Content Script Iframe
    </h1>
    <button class="btn btn-primary">
      Sample Daisy UI Button
    </button> -->
    <div id="aaa">{{ pageDocument }}</div>
    {{ selectInnerHTML }}
  </div>
</template>

<style scoped></style>
